<?PHP
require "../../mainfile.php";
include XOOPS_ROOT_PATH.'/header.php';
include_once(XOOPS_ROOT_PATH."/class/module.textsanitizer.php");
if(isset($_GET['ID'])){//echo form to send story to a friend
?>
<HTML>
<HEAD>
<TITLE><?PHP echo strtoupper($xoopsModuleConfig['stationLetters']); ?> News: Email This Article</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="news.css">
</HEAD>
<body>
 <TABLE  WIDTH="450" BORDER="0" CELLSPACING="0" CELLPADDING="5" BGCOLOR="#FFFFFF">

 <TR>
  <TD> 
<P CLASS="headline-large">Email this article:</P>
  </TD>
 </TR>

<TR>
 <TD>
<P>
Enter the email address of the person you want to send this article to:
</P>

<P>
<FORM ACTION="emailStory.php" METHOD="post">
<?PHP echo $GLOBALS['xoopsSecurity']->getTokenHTML()."\n"; ?>
<INPUT TYPE="hidden" NAME="action" VALUE="sendNews">
<INPUT TYPE="hidden" NAME="ID" VALUE="<?PHP echo $_GET['ID']; ?>">
<INPUT TYPE="hidden" NAME="syndicated" VALUE="<?PHP echo $_GET['syndicated']; ?>">
</P>
<P CLASS="headline-medium">
Recipient's Email: <INPUT TYPE="text" NAME="TO" SIZE="40" VALUE="">
</P>
<P>
Enter your name and email address below:</P>

<P CLASS="headline-small">
(We use your name and address only to tell the recipient who sent the message. <BR>We do not save or reuse them in any way.)
</p>

<P CLASS="headline-medium">
Your Name: <INPUT TYPE="text" NAME="FROM_NAME" SIZE="30" VALUE="">
</P> 

<P CLASS="headline-medium">
Your Email: <INPUT TYPE="text" NAME="FROM" SIZE="30" MAXLENGTH="50" VALUE="">
</P>

<P>
<INPUT TYPE="submit" NAME="send" VALUE="Send">&nbsp;&nbsp;</P>
</FORM>
</td></tr></table>
</body>
</HTML>
<?PHP
}elseif($GLOBALS['xoopsSecurity']->check() && $_POST['action'] == 'sendNews'){//check auth and send story
	require_once XOOPS_ROOT_PATH."/class/xoopsmailer.php";
	$xoopsMailer =& getMailer();
	$xoopsMailer->useMail(); 
	$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH.'/modules/local_news/templates');
	$xoopsMailer->setTemplate("mailRecipient.tpl");
	$xoopsMailer->setToEmails($_POST['TO']);
	$xoopsMailer->setFromEmail('noReply@'.strtolower($xoopsModuleConfig['stationLetters']).'.org');//$_POST['FROM']
	$xoopsMailer->setFromName($_POST['FROM_NAME']); 
	$xoopsMailer->setSubject($_POST['FROM'].' thought you would find this news story from '.$xoopsModuleConfig['stationLetters'].' interesting');
	if($_POST['syndicated'] == 'true'){
	$xoopsMailer->assign("MESSAGE", XOOPS_URL.'/modules/local_news/index.php?op=sideBlock&ID='.$_POST['ID'].'&syndicated=true'); 
	}else{
	$xoopsMailer->assign("MESSAGE", XOOPS_URL.'/modules/local_news/index.php?op=sideBlock&ID='.$_POST['ID']); 
	}
	if ( !$xoopsMailer->send() ) {
    	echo 'There was an error';
    } else {
    	echo '<h3 style=\'text-align:center;\'>The selected news story has been sent to '.$_POST['TO'].'</h3><P><CENTER><FORM>
<INPUT type="button" value="Close Window" onClick="window.close()"></FORM></CENTER>';
    } 
	


}
?>